<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_themeGridUnique"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript">
    var map, themeLayer, options,
        url = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-jingjin/rest/maps/京津地区地图";
    new ol.supermap.MapService(url).getMapInfo().then(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
            controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
            view: new ol.View({
                center: [117, 40],
                zoom: 7,
                projection: "EPSG:4326",
                multiWorld: true
            })
        });
        options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);
        createTheme();
    });

    function setItems() {
        var items = [],
            color0 = new ol.supermap.ServerColor(198, 244, 240),
            color1 = new ol.supermap.ServerColor(176, 244, 188),
            color2 = new ol.supermap.ServerColor(218, 251, 178),
            color3 = new ol.supermap.ServerColor(220, 236, 145),
            color4 = new ol.supermap.ServerColor(96, 198, 66),
            color5 = new ol.supermap.ServerColor(20, 142, 53),
            color6 = new ol.supermap.ServerColor(85, 144, 55),
            color7 = new ol.supermap.ServerColor(171, 168, 38),
            color8 = new ol.supermap.ServerColor(235, 165, 9),
            color9 = new ol.supermap.ServerColor(203, 89, 2),
            color10 = new ol.supermap.ServerColor(157, 25, 1),
            color11 = new ol.supermap.ServerColor(118, 15, 3),
            color12 = new ol.supermap.ServerColor(112, 32, 7),
            color13 = new ol.supermap.ServerColor(106, 45, 12),
            color14 = new ol.supermap.ServerColor(129, 80, 50),
            color15 = new ol.supermap.ServerColor(160, 154, 146);
        for (var i = -4; i < 2197; i++) {
            var num = parseInt(i / 135);
            var item = new ol.supermap.ThemeGridUniqueItem();
            item.caption = 1;
            item.unique = i;
            item.visible = true;
            switch (num) {
                case 0:
                    item.color = color0;
                    break;
                case 1:
                    item.color = color1;
                    break;
                case 2:
                    item.color = color2;
                    break;
                case 3:
                    item.color = color3;
                    break;
                case 4:
                    item.color = color4;
                    break;
                case 5:
                    item.color = color5;
                    break;
                case 6:
                    item.color = color6;
                    break;
                case 7:
                    item.color = color7;
                    break;
                case 8:
                    item.color = color8;
                    break;
                case 9:
                    item.color = color9;
                    break;
                case 10:
                    item.color = color10;
                    break;
                case 11:
                    item.color = color11;
                    break;
                case 12:
                    item.color = color12;
                    break;
                case 13:
                    item.color = color13;
                    break;
                case 14:
                    item.color = color14;
                    break;
                case 15:
                    item.color = color15;
                    break;
                default:
                    item.color = color0;
                    break;
            }
            items.push(item);
        }
        return items;
    }

    function createTheme() {
        var themeGridUnique = new ol.supermap.ThemeGridUnique({
            defaultcolor: new ol.supermap.ServerColor(0, 0, 0),
            items: setItems()
        });
        var themeParameters = new ol.supermap.ThemeParameters({
            datasetNames: ["JingjinTerrain"],
            dataSourceNames: ["Jingjin"],
            themes: [themeGridUnique]
        });

        var extent = [114.59, 37.76, 119.51, 42.31];
        new ol.supermap.ThemeService(url).getThemeInfo(themeParameters).then(function (serviceResult) {
            var result = serviceResult.result;
            if (result && result.newResourceID) {
                themeLayer = new ol.layer.Tile({
                    source: new ol.source.TileSuperMapRest({
                        url: url,
                        noWrap: true,
                        cacheEnabled: false,
                        transparent: true,
                        layersID: result.newResourceID,
                        tileGrid: new ol.tilegrid.TileGrid({
                            extent: extent,
                            resolutions: options.tileGrid.getResolutions()
                        }),
                        transparent: true
                    })
                });
                map.addLayer(themeLayer);
            }
        });
    }
</script>
</body>
</html>